package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.utils.DateUtil;
import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class News extends BaseDomain {
    public static final int STATE_NORMAL = 0;//普通状态
    public static final int STATE_HOT = 1;//推荐

    public static final int TYPE_FOOD = 0;//美食
    public static final int TYPE_LAW = 1;//法务
    public static final int TYPE_COMMON = 2;//基础
    private int type;//分类

    // @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;//创建时间

    private String coverUrl;//封面

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date recommendTime;//推荐时间

    private String title;//标题

    private User user;//作者
    private int state = 0;//状态

    private NewsContent newsContent;

    public String getTypeDisplay() {
        String temp = "";
        if (type == 0) {
            temp = "美食";
        } else if (type == 1) {
            temp = "法务";
        } else if (type == 3) {
            temp = "基础";
        }
        return temp;
    }
    public String getStateDisplay() {
        String temp = "";
        if (state == 0) {
            temp = "普通";
        } else if (state == 1) {
            temp = "推荐";
        }
        return temp;
    }
    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",getId());
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        map.put("type",type);
        map.put("state",getStateDisplay());
        if(user!=null){
            map.put("userId",user.id);
        }
        return JSONUtils.toJSONString(map);
    }


}